<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('素材列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
    <div class="ui-layout-west">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 素材分组
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>

    <div class="ui-layout-center">
        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <input type="hidden" name="groupId" id="groupId">
                                </li>
                                <li>
                                    <label>站点id：</label>
                                    <input id="siteId" name="siteId"  type="hidden"/>
                                    <input type="text" onclick="selectSiteTree()" id="siteName" readonly="true">
                                </li>
                                <li>
                                    <label>素材名称：</label>
                                    <input type="text" name="materialName"/>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="cms:material:add">
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="cms:material:edit">
                        <i class="fa fa-edit"></i> 修改
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="cms:material:remove">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                    <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="cms:material:export">
                        <i class="fa fa-download"></i> 导出
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>

    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('cms:material:edit')}]];
        var removeFlag = [[${@permission.hasPermi('cms:material:remove')}]];
        var groupIdDatas = [[${@dict.getType('cms/materialGroup/selectMaterialGroupTree/')}]];
        var materialTypeDatas = [[${@dict.getType('material_type')}]];
        var prefix = ctx + "cms/material";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "素材",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'groupId',
                    title: '分组id',
                },
                {
                    field: 'siteId',
                    title: '站点id'
                },
                {
                    field: 'materialName',
                    title: '素材名称'
                },
                {
                    field: 'materialType',
                    title: '素材类型 字典 1图片2视频',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(materialTypeDatas, value);
                    }
                },
                {
                    field: 'description',
                    title: '素材描述'
                },
                {
                    field: 'materialSize',
                    title: '素材大小'
                },
                {
                    field: 'savePath',
                    title: '保存路径',
                    formatter: function(value, row, index) {
                        return $.table.imageView(row.savePath);
                    }
                },
                {
                    field: 'width',
                    title: '分辨率 宽'
                },
                {
                    field: 'height',
                    title: '分辨率 高'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'sort',
                    title: '排序'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185 });
            queryDeptTree()
        });

        function queryDeptTree()
        {
            var url = ctx + "cms/materialGroup/treeData";
            var options = {
                url: url,
                expandLevel: 2,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                $("#groupId").val(treeNode.id);
                $.table.search();
            }
        }


            /*站点选择*/
            function selectSiteTree() {
                var options = {
                    title: '站点选择',
                    width: "380",
                    url: ctx + "system/site" + "/selectWjSiteTree/",
                    callBack: doSubmitSiteTree
                };
                $.modal.openOptions(options);
            }

            function doSubmitSiteTree(index, layero){
                var body = layer.getChildFrame('body', index);
                $("#siteId").val(body.find('#treeId').val());
                $("#siteName").val(body.find('#treeName').val());
                layer.close(index);
            }

    </script>
</body>
</html>